cc.Class({
    extends: cc.Component,

    properties: {
        posSpts: [cc.SpriteFrame],
        iconSpts: [cc.SpriteFrame],
        txtPhase: cc.Label,
        itemPos: cc.Node,
        boxPos: cc.Node,
        itemBet: cc.Node,
        boxBet: cc.Node,

        lb_bar1: cc.Label,
        lb_bar2: cc.Label,
        lb_bar3: cc.Label,

    },

    onLoad () {
        this.itemPos.parent = null;
        this.itemBet.parent = null;
        this.initWords();
    },

    initWords: function()
    {
        this.lb_bar1.string = LangLocal.word19;
        this.lb_bar2.string = LangLocal.word20;
        this.lb_bar3.string = LangLocal.word21;
    },

    init(data) {
        this.initPos(data.bikeInfo);
        this.initBet(data.betInfo);
        this.txtPhase.string = LangLocal.word22 + data.phase.substr(4, data.phase.length - 4) + LangLocal.word23;
    },

    initPos(bikeInfo) {
        for(var i in bikeInfo) {
            var d = bikeInfo[i];
            var obj = cc.instantiate(this.itemPos);
            obj.find('pos', cc.Sprite).spriteFrame = this.posSpts[d.rank - 1];
            obj.find('icon', cc.Sprite).spriteFrame = this.iconSpts[d.bikeId - 1];
            obj.find('odds', cc.Label).string = LangLocal.word8+'x' + d.rate.toFixed(2);
            obj.find('name', cc.RichText).string = '<color=#ffffff><outline color=black width=2><b>00' + d.bikeId + '</b></outline></color>';
            obj.setLocalZOrder(d.rank);
            obj.parent = this.boxPos;
        }
    },

    initBet(bikeBet) {
        for(var j in bikeBet) {
            var d = bikeBet[j];
            var obj = cc.instantiate(this.itemBet);
            obj.parent = this.boxBet;
            obj.children[0].find('txtTitle', cc.Label).string = LangLocal.word24+'：00' + d.bikeId;
            obj.children[1].find('txtBet', cc.Label).string = d.amount;
            var txtWin = obj.children[2].find('txtWin', cc.Label);
            txtWin.string = d.returnAmount;
            if(d.returnAmount == 0) txtWin.node.color = cc.Color.BLACK;
        }
    }
});
